package com.banciyuan.bcywebview.biz.post.pic;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.daoexample.model.Multi;

/**
 * Created by squall on 2016/2/22.
 */
public class HttpImageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    List<Multi> slist = new ArrayList<>();
    Context mContext;
    LayoutInflater inflater;

    public HttpImageAdapter(List<Multi> slist, Context mContext) {
        this.slist = slist;
        this.mContext = mContext;
        this.inflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ImageHolder(inflater.inflate(R.layout.post_img_item_exactly, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ImageHolder imageHolder = (ImageHolder) holder;
        ImageLoader.getInstance().displayImage(slist.get(position).getPath(), imageHolder.img_content, ImageOptions.options);
        imageHolder.img_cancel.setVisibility(View.GONE);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return slist.size();
    }

    private class ImageHolder extends RecyclerView.ViewHolder {
        ImageView img_content;
        ImageView img_cancel;

        public ImageHolder(View convertView) {
            super(convertView);
            img_content = (ImageView) convertView.findViewById(R.id.item_group_content);
            img_cancel = (ImageView) convertView.findViewById(R.id.item_group_cancel);
        }
    }
}
